home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 40 / Commodore_Free_Issue_40_2010_Commodore_Computer_Club.d64 / asteroid belt < prev    next >
Text File  |  2023-02-26  |  4KB  |  178 lines

  1.  
  2.  
  3. *************************************
  4.   COMMODORE FREE BASIC PROGRAMMING
  5.               CHALLENGE
  6.       C64/VIC20/C16/+4 Version
  7.             By Paul Davis
  8. *************************************
  9.  
  10. Here are a few simple changes to the
  11. Asteroid Belt listing presented in
  12. issue 37. The extra code allows the
  13. game to run on either the C64,
  14. unexpanded VIC20, C16 or Plus/4 and
  15. will detect which machine it is
  16. running on. To make the game
  17. slightly more challenging, an extra
  18. feature has been added that will
  19. deplete the ship's fuel over time.
  20. Run out of fuel and its game over.
  21.  
  22. Only the lines that need to change
  23. are listed here. Load in the
  24. original program (or copy and paste
  25. it into an emulator) then add the
  26. following lines (owners of an
  27. unexpanded VIC20 will need to remove
  28. some of the old REM comment lines
  29. first to free up some memory):
  30.  
  31. 10 a=0: b=a: c=a: i=a: s=a: f=40:
  32. a$=""
  33.  
  34. 19 rem determine which machine this
  35. is running on
  36. 20 if peek(65532)=226 then m=64
  37. 21 if peek(65532)=34 then m=20
  38. 22 if peek(65532)=246 then m=16
  39. 29 rem variables for platform
  40. dependent memory locations
  41. 30 if m=64 then
  42. sc=1024:co=55296:wi=40:hg=25
  43. 31 if m=20 then
  44. sc=7680:co=38400:wi=22:hg=23
  45. 32 if m=16 then
  46. sc=3072:co=2048:wi=40:hg=25
  47.  
  48. 90 gosub 420
  49.  
  50. 100 fori=1 to hg-1:print:nexti
  51.  
  52. 110
  53. b=sc+wi*int(hg/2):c=int(wi/2):bs=sc+w
  54. i*(hg-1)
  55.  
  56. 120 a=int(wi*rnd(1))
  57.  
  58. 130 poke bs+a,46
  59.  
  60. 140 if rnd(1)>.1 then
  61. p=int(rnd(1)*wi):poke p+bs,42
  62.  
  63. 160 if a$="m" and c<wi then poke
  64. b+c,32:c=c+1
  65.  
  66. 171 rem to make the game more
  67. challenging we will use up 1 unit
  68. 172 rem of fuel every time the
  69. screen scrolls
  70. 173 print:f=f-1
  71. 174 rem if we have run out of fuel,
  72. game over
  73. 175 if f=0 then r$="ran out of
  74. fuel":goto 310
  75.  
  76. 180 if peek(b+c)=42 then r$="hit an
  77. asteroid":goto 310
  78.  
  79. 320 print "sorry you"
  80. 325 print r$
  81. 330 print:print "you
  82. scored";s;"points"
  83.  
  84. 400 if m=64 then for i=0 to 16:poke
  85. 53280,i:next i
  86. 401 if m=20 then for i=0 to 8:poke
  87. 36879,i:next i
  88. 402 if m=16 then for i=0 to 16:poke
  89. 65305,i:next i
  90. 405 s=s+10:f=f+10:return
  91.  
  92. 419 rem clear screen to white on
  93. black
  94. 420 if m=64 then poke 53280,0:poke
  95. 53281,0
  96. 421 if m=20 then poke 36879,8
  97. 422 if m=16 then poke 65305,0:poke
  98. 65301,0
  99. 425 print chr$(5);chr$(147);:return
  100.  
  101. Explanation of the additional lines:
  102.  
  103. Line 10: adds the F variable to hold
  104. the current amount of fuel on board
  105. the ship.
  106.  
  107. Lines 20-22: determine which machine
  108. the program is running on by
  109. checking the 6502 reset vector at
  110. memory location 65532 (FFFC in hex).
  111. The end result is that the variable
  112. M is set to the value 64, 20 or 16
  113. for C64, VIC20 or C16/Plus4
  114. respectively.
  115.  
  116. Lines 30-32: set the value of a few
  117. constants depending on which machine
  118. is in use. SC is the start of screen
  119. memory, CO is the start of colour
  120. memory, WI and HG are the width and
  121. height of the screen. The values for
  122. the VIC20 are for an unexpanded
  123. machine only. If you have extra
  124. memory, the location of the screen
  125. and colour data will need to change.
  126.  
  127. Line 90: changed to call a
  128. subroutine to clear the screen.
  129.  
  130. Line 100: changed to use the HG
  131. (screen height) variable rather than
  132. the C64 specific value.
  133.  
  134. Line 110: changed to use the SC, WI
  135. and HG variables to calculate the
  136. on-screen positions rather than the
  137. C64 specific values. Also added the
  138. BS variable to hold the address of
  139. the bottom screen line.
  140.  
  141. Line 120,130,140,160: changed to use
  142. the WI and BS variables rather than
  143. the C64 specific values.
  144.  
  145. Line 173: scroll the screen and
  146. deplete the ship's fuel reserve.
  147.  
  148. Line 175: check if the fuel has run
  149. out. If it has, jump to the
  150. game-over section with the reason
  151. why the game ended in the R$
  152. variable.
  153.  
  154. Line 180: changed to put the reason
  155. for ending the game in the R$
  156. variable.
  157.  
  158. Lines 320-330: changed to print the
  159. reason why the game ended from the
  160. R$ variable. This allows the same
  161. section of code to be used,
  162. regardless of why the game is over.
  163.  
  164. Lines 400-405: changed to have a
  165. different effect depending on which
  166. machine is in use. The code that is
  167. the same for all machines is on line
  168. 405. Collecting a fuel pod increases
  169. the ship's fuel reserve by 10 units.
  170.  
  171. Lines 420-425: clear the screen to
  172. white on black using the correct
  173. video chip registers for each
  174. machine. The code common to all
  175. machines is on line 425.
  176.  
  177. =====================================
  178.